<?php /**
* 上传类
*/
class Upload 
{
	public $dir ;
	public $type = array('txt','jpg',"png","wmv");
	public $maxsize = 0.1;
	public $row_1=[];//上传图片名
	public $size_1=[];//上传图片大小
	public $tmp_1=[];//上传图片临时文件名
	


	// 	return "./Upload/".date('Y-m-d').'/';


	
	function __construct($dir='',$type='')
	{
		 $this->dir="./Upload/".date('Y-m-d').'/';
		if (!empty($this->dir)) {
			is_dir($this->dir) || mkdir($this->dir);
		}
		
		$this->dir = empty($dir) ?  $this->dir: $dir;
		// $this->type = empty($type) ? $this->type :$type ;


	}

	public function Upload_fun()
	{
		// 接数据
		$this->getFiles();
		//检测类型
		$this->checkType();
		//检测大小
		$this->checkSize();
		//移动文件
		$this->movefile();
	}

	public function getFiles()
	{
		// var_dump($_FILES);
		$tempArr = [];
		foreach (current($_FILES) as $k => $v) {
			foreach ($v as $k1 => $v1) {
				$tempArr[$k1][$k] = $v1;
			}
		} 
		return $tempArr;

	}

	public function checkType()
	{
		
		foreach ($this->getFiles() as $k => $row) {
			if($row['error']==0){
				$tmparr = explode('.',$row['name']);

				$name = end($tmparr);
				//得到文件格式
				if(in_array($name , $this->type)){
					$this->row_1[$k] = uniqid().$k.'.'.$name;//上传图片名
					$this->size_1[$k]=$row["size"];
					$this->tmp_1[$k]=$row["tmp_name"];
					

				}else{
					echo "你上传的类型不符合要求";
				}

			}else{
				echo "上传失败，失败代码：".$row['error'];
			}
		}
	
	}

	public function checkSize(){

	// 	if ($size<$this->maxsize*1024) {
	// 		echo "上传文件大小不符！";

	// 	}	
	}

	public function movefile()
	{
		foreach ($this->tmp_1 as $k2 => $v2) {

			if ($this->size_1[$k2]>$this->maxsize*1024*1024) {
				echo "上传文件大小不符！";exit;
			}else{
				move_uploaded_file($this->tmp_1[$k2], $this->dir.$this->row_1[$k2]);
			}


			
		}
		
		
	}






}


 ?>